<?


require_once  $_SERVER['DOCUMENT_ROOT']."/../_lib/base/common.php";
require_once SITE_ROOT_PATH."/_lib/classes/class.template.php";
require_once SITE_ROOT_PATH."/_lib/classes/class.hotel_references.php";
require_once SITE_ROOT_PATH."/_lib/classes/class.destinations.php";
require_once SITE_ROOT_PATH."/_lib/classes/class.exchange_rates.php";
require_once SITE_ROOT_PATH."/_lib/classes/class.hotels.php";
require_once SITE_ROOT_PATH."/_lib/classes/class.airports.php";
require_once SITE_ROOT_PATH."/_lib/classes/class.photos.php";
require_once SITE_ROOT_PATH."/_lib/classes/class.user_auth.php";

	// See if user is logged in 
	$user_auth = new user_auth();
	$user_auth->user_auth_bookings();


	$template = new template();
	$template->head_booking();
	

// FUNCTION // Show home page
function display_home(){	
	
?>

<h2>Hotel Reference Lookup</h2>


<?
if($GLOBALS['note']){
	echo display_message($GLOBALS['note']);
}
?>


<form action="<?= $_SERVER['PHP_SELF']?>" method="get">

	<input type="hidden" name="action" value="search" />

	<table class="libra">
		<tr>
			<td width="150"><strong>Hotel reference:</strong></td>
			<td><input type="text" name="reference_id" value="<?= $_REQUEST['reference_id'] ?>"></td>
		</tr>
		<tr>
        <td></td>
			<td><input type="submit" value="submit" class="form_button"></td>
		</tr>
	</table>


</form>



<?
}
// END FUNCTION 














// FUNCTION // Display result
function display_result($values){


$hotels = new hotels();
$destinations = new destinations();
$airports = new airports();
$photos = new photos();


?>

<h2>Hotel Reference Lookup</h2>


<h3>Results</h3>

<!-- START LEFT COL -->


<div class="col_490 margin_right_20">



<div class="border_box">

<fieldset><legend>Hotel Booking Details</legend></fieldset>

<table class="libra">
      <tr> 
        <th width="170">Reference number</th>
        <td><strong><?= $values['reference_id'] ?></strong></td>
      </tr>

      <tr>
        <th>Time of lookup</th>
        <td><?= date('d M Y H:i',$values['reference_date']) ?></td>
      </tr>
     <tr> 
        <th>Hotel Supplier</th>
        <td><?=	$values['hotel_supplier'] ?></td>
     </tr>
	 	  <tr> 
        <th>Supplier hotel code</th>
        <td><?= $values['hotel_id_supplier'] ?></td>
      </tr>
	  	  <tr> 
        <th>LateDeals.ie hotel code</th>
        <td><?= $values['tree_id'] ?></td>
      </tr>
	  	  <tr> 
        <th>Check in date</th>
        <td><?= date('d M Y',$values['check_in_date']) ?></td>
      </tr>
	  <tr> 
        <th>Nights</th>
        <td><?= $values['nights'] ?></td>
      </tr>
	  <tr> 
        <th>Hotel Name</th>
        <td><?= $values['hotel_name'] ?></td>
      </tr>
	  <tr> 
        <th>Room count</th>
        <td><?= $values['room_count'] ?></td>
      </tr>
	  <tr> 
        <th>Room breakdown</th>
        <td><?= nl2br($values['room_breakdown']) ?></td>
      </tr>
	  
      
</table>
<br />

</div>

  
</div>

<!-- END LEFT COL -->












<!-- START RIGHT COL -->

<div class="col_490">










<!-- Start hotel preview -->


<div class="border_box">

<fieldset><legend>Hotel Details</legend></fieldset>




<?

$hotels = new hotels();

	// 1. Accommidation lookup
	
	$params = array();
	$params['tree_id'] = $values['tree_id'];
	$hotel_values = array();
	$hotel_values = $hotels->get_hotel($params);

	

	if($hotel_values){
	
		// get photos
		$hotel_photos = $photos->get_photos($hotel_values['tree_id']);
		$lead_hotel_thumb_url = UPLOAD_HTTP_PERM.$hotel_photos[0]['photo_url_thumb'];
		if(!$hotel_photos){
			$lead_hotel_thumb_url = UPLOAD_HTTP_PERM."photo_thumb_no_photo.gif";
		}
		// Get resort
		$params['tree_id'] = $hotel_values['parent_id'];
		$resort_values = $destinations->get_destination($params);
		unset($params);
		//Get destination
		$params['tree_id'] = $resort_values['parent_id'];
		$destination_values = $destinations->get_destination($params);
		unset($params);


	

	


?>

	



<h5><?= $hotel_values['name'].", ".$resort_values['name'].", ".$destination_values['name'] ?></h5>





<div class="div_photo_right"><a href="javascript:MM_openBrWindow('http://www.latedeals.ie/hotels/accommodation_gallery.php?accommodation_id=<?= $accommodation_values['accommodation_id'] ?>','','scrollbars=yes,width=400,height=500')"><img src="<?= $lead_hotel_thumb_url ?>" alt="<?= $hotel_values['name'] ?>" width="108" height="80" /></a>	
<a href="javascript:MM_openBrWindow('http://www.latedeals.ie/hotels/accommodation_gallery.php?accommodation_id=<?= $accommodation_values['accommodation_id'] ?>','','scrollbars=yes,width=400,height=500')">View photos <img class="inline" src="/images/icon_larger.gif" alt="View photos" /></a></div>




<p><?= nl2br($hotel_values['description']) ?></p>



<!-- END ACCOMMODATION -->
	
    
    
    
	

	
<!-- START RESORT -->

<h6><?= $resort_values['name'] ?></h6>

<p><?= nl2br($resort_values['description']) ?></p>


<!-- START destination -->
 
<h6 title="<?= $destination_values['name'] ?>"><?= $destination_values['name'] ?></h6>

<p><?= nl2br($destination_values['description']) ?></p>





<? }else{ ?>

<h5>No hotel description available</h5>




<? } ?>


</div>





</div>

<!-- END RIGHT COL -->



<?


}
// END FUNCTION






switch ($_REQUEST['action']){
	default:
		display_home();
	break;
	case "search":
		$hotel_references = new hotel_references();
		$params['reference_id'] = $_GET['reference_id'];
		$hotel_values = $hotel_references->search_hotel_reference($params);

		// No reference given
		if(empty($_GET['reference_id'])){
			$my_message = array();
			$my_message['type'] = 'neg';
			$my_message['message'] = "Please enter a reference";
			$GLOBALS['note'] = $my_message;	
			$error = true;	
		}elseif(!$hotel_values){
			$my_message = array();
			$my_message['type'] = 'neg';
			$my_message['message'] = "Reference not found in the system";
			$GLOBALS['note'] = $my_message;
			$error = true;	
		}
		
		
		if($error){
			display_home();
		}else{
			display_result($hotel_values);
		}
		
	break;
	
}


	$template->foot_booking();
	

?>